from appium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class Base1():
    def __init__(self):
        cap={
            "platformName": "Android",
            "appium:deviceName": "emulator-5554",
            "appium:appPackage": "com.kongfz.app",
            "appium:appActivity": "com.achievo.vipshop/com.achievo.vipshop.activity.LodingActivity",
            "noReset": True
        }
        self.driver=webdriver.Remote('http:127.0.0.1:4723/wd/hub',cap)
        self.driver.implicitly_wait(25)
        sleep(20)

    def loc_ele(self,loc):
        try:
            return self.driver.find_element(*loc)
        except Exception as e:
            print("报错信息：",e)
            print("未定位到元素变量值")

    def loc_wait_ele(self,loc):
        try:
            return WebDriverWait(self.driver,15).until(EC.presence_of_element_located(loc))
        except Exception as e:
            print("报错信息：",e)
            print("未定位到元素变量值")

    def loc_ui_ele(self,loc):
        try:
            return self.driver.find_element_by_android_uiautomator(loc)
        except Exception as e:
            print("报错信息：",e)
            print("未定位到元素变量值")

    # 退出
    def quit_driver(self):
        self.driver.quit()